//
// Created by king on 18-11-14.
//

#include "common.h"
#include "gl_util.h"

auto gVertexShader =
        "void main() {\n"
        "  gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
        "  gl_PointSize = 30.0;\n"
        "}\n";

auto gFragmentShader =
        "precision mediump float;\n"
        "void main() {\n"
        "  gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
        "}\n";


GLuint gProgram;

extern "C" JNIEXPORT void JNICALL
Java_com_example_king_openglenvdemo_nativegl_GLES2JNILib_init(
        JNIEnv* env,
        jobject obj,
        jint width,
        jint height) {

    glViewport(0, 0, width, height);

    LOGD("----------------------init width:%d, height:%d", width, height);

    gProgram = linkProgram(gVertexShader, gFragmentShader);
    if (!gProgram) {
        LOGE("Could not create program.");
        return;
    }

    glUseProgram(gProgram);


}

extern "C" JNIEXPORT void JNICALL
Java_com_example_king_openglenvdemo_nativegl_GLES2JNILib_step(
        JNIEnv* env,
        jobject obj) {

    LOGD("----------------------step");

    glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glDrawArrays(GL_POINTS, 0, 1);
}